package com.yootk.service.fallback;

import com.yootk.common.dto.DeptDTO;
import com.yootk.service.IDeptService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component // 进行Bean注册
public class DeptServiceFallbackFactory implements FallbackFactory<IDeptService> {
    @Override
    public IDeptService create(Throwable cause) { // 定义失败回退处理
        return new IDeptService() {
            @Override
            public DeptDTO get(long id) {
                DeptDTO dto = new DeptDTO();
                dto.setDeptno(id);
                dto.setDname("【部门名称】" + cause.getMessage()); // 设置异常信息
                dto.setLoc("【部门位置】" + cause.getMessage());
                return dto;
            }

            @Override
            public boolean add(DeptDTO dto) {
                return false;
            }

            @Override
            public List<DeptDTO> list() {
                return new ArrayList<DeptDTO>();
            }
            @Override
            public Map<String, Object> split(int currentPage, int lineSize, String column, String keyword) {
                return new HashMap<>();
            }
        };
    }
}
